﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

using HA.MT3DMS.DomainLayer;

namespace HA.ModFlow.Controls
{
    public class MTPCBTN:INotifyPropertyChanged
    {
        public MTPCBTN(BasicTransport btn)
        {
            this._btn = btn;
            this._modelType = btn.ModelOption.ModelType;
            foreach(MTSpecies item in btn.SpeciesCollecion.Species)
            {
              this._species.Add(item) ;
            }

            this._cinact = btn.CINACT;
            this._thkmin = btn.THKMIN;
            this.HtopEqualsTop = btn.HtopEqualsTop;
            this._outputControl =(MTOutputControl) btn.OutputControl.Clone();
        }

        BasicTransport _btn;

        ModelType _modelType;

        public ModelType ModelType
        {
            get { return _modelType; }
            set { 
                _modelType = value;
                OnPropertyChanged("ModelType");
            }
        }

        private bool _htopEqualsTop = true;
        /// <summary>
        /// MT3D顶板海拔等于MODFLOW的顶板海拔
        /// </summary>
        public bool HtopEqualsTop
        {
            get { return _htopEqualsTop; }
            set { _htopEqualsTop = value; }
        }

   

        ObservableCollection<MTSpecies> _species = new ObservableCollection<MTSpecies>();

        public ObservableCollection<MTSpecies> Species
        {
            get { return _species; }
        }

        MTOutputControl _outputControl;

        public MTOutputControl OutputControl
        {
            get { return _outputControl; }
            set { _outputControl = value; }
        }

        double _cinact;

        public double Cinact
        {
            get { return _cinact; }
            set { 
                  _cinact = value;
                  OnPropertyChanged("Cinact");
                }
        }

        double _thkmin;

        public double Thkmin
        {
            get { return _thkmin; }
            set { 
                  _thkmin = value;
                  OnPropertyChanged("Cinact");
                }
        }

        #region INotifyPropertyChanged

        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region 公共方法

        public void ConformToDataCenter()
        {
            this._btn.ModelOption.ModelType = this.ModelType;
            this._btn.CINACT = this.Cinact;
            this._btn.THKMIN = this.Thkmin;



            //姐姐，不允许直接操作集合数据，要用暴露的接口函数，reset，要不然怎么触发事件？？？？？？？



            _btn.SpeciesCollecion.ResetSpecies(this._species.ToList<MTSpecies>());

            //_btn.SpeciesCollecion.Species.Clear();
            //this._btn.SpeciesCollecion.Species.AddRange(this._species);


            this.ConformOutputControlToDataCenter();
            this._btn.HtopEqualsTop = this.HtopEqualsTop;
        }

        public void SetSpecies(List<MTSpecies> species)
        {
            this.Species.Clear();
            foreach (MTSpecies item in species)
            {
                this.Species.Add((MTSpecies)item.Clone());


               
             
            }
        }

        public void SetOutputControl(MTOutputControl outputControl)
        {
            this._outputControl =(MTOutputControl) outputControl.Clone();
        }

        public void ConformOutputControlToDataCenter()
        {
            this._btn.OutputControl.CN = this._outputControl.CN;
            this._btn.OutputControl.DP = this._outputControl.DP;
            this._btn.OutputControl.NP = this._outputControl.NP;
            this._btn.OutputControl.RF = this._outputControl.RF;
            this._btn.OutputControl.IsSavMass = this._outputControl.IsSavMass;
            this._btn.OutputControl.IsSavUcn = this._outputControl.IsSavUcn;
            this._btn.OutputControl.StepsType = this._outputControl.StepsType;
            if (this._outputControl.StepsType == TimeStepType.SpecifiedTimes)
            {

                


                this._btn.OutputControl.Timesteps.Clear();
                this._btn.OutputControl.Timesteps.AddRange(this._outputControl.Timesteps);

               


            }
            else if (this._outputControl.StepsType == TimeStepType.SpecifiedInterval)
            {
                this._btn.OutputControl.Interval = this._outputControl.Interval;
            }
        }

        #endregion
    }
}
